package ipad.asia.controller;

import ipad.asia.service.consumer.ConsumerFeign;
import ipad.asia.service.enterprise.EnterpriseFeign;
import ipad.asia.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class RegisterController {
    @Autowired
    private ConsumerFeign consumerFeign;
    @RequestMapping("/register")
    public ModelAndView register(@RequestParam(value = "user", required = false) String user,
                                    @RequestParam(value = "password", required = false) String password,
                                    @RequestParam(value = "email", required = false) String email,
                                    @RequestParam(value = "phone", required = false) String phone) {
        System.out.println("测试注册！");
        if(user==null){
            return new ModelAndView("register");
        }else {
            if (consumerFeign.register(user, MD5Util.inputPassToFormPass(password), email,phone) == true) {
            return new ModelAndView("login", "message", "注册成功，请登录");
        }else {
            return new ModelAndView("register", "message", "注册失败，用户已存在");
        }}
    }
}
